package com.ben.multiple.poi.rest;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author BenJin Yin
 * @date 2020/9/23
 */
@RestController
@RequestMapping("/multi")
@Slf4j
public class MultipleRest {

    @PostMapping("/array")
    public String array(@RequestParam(value = "files", required = false) List<MultipartFile> files) {
        if (files == null) {
            return "empty";
        }
        for (MultipartFile obj : files) {
            System.out.println(obj.getOriginalFilename());
        }
        return "ok";
    }

    @PostMapping("/dive")
    public String dive(@RequestParam(value = "file1", required = false) MultipartFile file1,
                       @RequestParam(value = "file2", required = false) MultipartFile file2) {
        if (file1 != null) {
            System.out.println(file1.getOriginalFilename());
        }
        if (file2 != null) {
            System.out.println(file2.getOriginalFilename());
        }
        return "ok";
    }

}
